package com.engineering.elink.common;

/**
 * 错误类型,0为正常处理返回,1**为客户端错误,2**为服务器错误(具体错误自定义,如101为请求参数错误)
 * @author hxjxiaojun
 * 
 */
public enum ResultType{
	SUCCESS							(0, "success"),
	CLIENT_ERROR					(1, "客户端未知错误"),
	SERVER_ERROR					(2, "服务器未知错误"),
	NEED_LOGIN						(-1, "请重新登录"),
	
	REQUEST_PARAMS_ERROR			(101, "请求参数不合法"),
	AUTHORITY_ERROR                 (102, "没有操作权限"),
	SESSION_TIMEOUT_ERROR		    (103, "session已超时"),
	REQUESTED_DATA_NOT_EXIST_ERROR	(104, "请求的数据不存在"),
	PASSWORD_ERROR    				(109, "用户名或密码错误"),
	CHECKCODE_NOT_EXSIT_ERROR    	(110, "验证码已过期，请重新获取"),
	CHECKCODE_ERROR    				(111, "手机验证码错误"),
	TOKEN_ERROR    				    (112, "令牌错误"),              //令牌错误，用户不存在
	EMAIL_EXIST    				    (113, "邮箱已存在"),             
	PHONE_EXIST    				    (114, "手机号已存在"),  
	PRAISE_ERROR                    (110, "请不要重复顶/踩"),
    COLLECTION_SUCCESS              (111, "收藏成功"),
    CANCEL_COLLECTION               (112, "您已取消收藏"),
	FILE_TYPE_ERROR			        (113, "暂时不支持该文件格式"),
	BLOG_ERROR                         (114, "该博文不存在"),
	BLOG_COMMENT_ERROR       (115,"你没有权限删除该条评论"),
    COMMENT_ERROR              (116," 请不要重复评论"),
    FILE_COMMENT_ERROR              (105, "您所评论的文件不存在"),
	COMMENT_REPLY_ERROR             (106, "您所回复的评论不存在"),
	COMMENT_PRAISE_ERROR            (107, "您所点赞的评论不存在"),
	REPLY_ERROR                                (108, "请不要重复回复"),
	CANCLE_PRAISE                             (117,"你已取消顶/踩"),	
	
	DATABASE_ERROR                  (201, "数据库操作出错"),
	SMS_ERROR				        (202, "短信发送失败"),
	HANDLE_FILE_ERROR			    (203, "服务器处理文件出错");
	
	private int code;
	private String msg;

	public int getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	private ResultType(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	/**
	 * 根据code获取到msg
	 * @param code
	 * @return
	 */
	public static String getMsgByCode(int code){
		for(ResultType e:ResultType.values()){
			if(e.getCode()==code){
				return e.getMsg();
			}
		}
		return null;
	}
}